<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/commons/jsp-head.jsp" %>

<div class="remotessh_div">
 <form id="remotessh_form" action="/remotessh/execute-cmd.action" method="post">  
            <table>  
                <tr>  
                    <td>ip:</td>  
                    <td>
                    	<select name="ip">
                    		<c:forEach items="${ips}" var="item">
                    			<option value="${item.ip}">${item.ip}</option>
                    		</c:forEach>
                    	</select>
                    </td>  
                </tr>  
                <tr>  
                    <td>port:</td>  
                    <td><input name="port" type="text" value="16333"></input></td>  
                </tr>  
                <tr>  
                    <td>username:</td>  
                    <td><input name="username" type="text" value="publish"></input></td>  
                </tr>  
                <tr>  
                    <td>password:</td>  
                    <td><input name="password" type="password" value="2Y39bVu78UK2"></input></td>  
                </tr> 
                <tr>  
                    <td>cmd:</td>  
                    <td><textarea name="cmd" rows="10" cols="100"></textarea></td>  
                </tr> 
                <tr>  
                    <td></td>  
                    <td><input type="button" value="提交" onclick="remotessh_submit()"></input><input type="button" value="生成快捷按钮" onclick="remote_shortcut()"></input></td>  
                </tr>  
            </table>  
</form> 
</div> 
<div id="remotessh_result" class="remotessh_div">

</div>
<style>
.remotessh_div {
	margin-top:20px;
	margin-left:20px;
	font-size:15px
}
.remotessh_div td{
	font-size:15px
}

.remotessh_div .msg {
	font-size:15px
}

.remotessh_div .out {
	font-size:15px
}

.remotessh_div p{
	margin:8px 0px 8px 0px
}

.remotessh_div span {
	margin:0px 10px 0px 10px;
}

.remotessh_div .msg {
	font-weight:bold
}

</style>
<script>
		function remotessh_submit()
		{
			$('#remotessh_form').form('submit', {  
			    success: function(data){  
			        var data = jQuery.parseJSON(data.replace(/\n/g,"<br>"));  // change the JSON string to javascript object  
			        if (data.status==0){  
			            alert("执行成功！");  
			        }  
			        else
			        {
			        	alert("执行失败！")	
			        } 
			  		var span="<span>|</span>";
			        var html="<div style='display:none'>"
			        html+="<p class='msg'>"+data.worker+span+data.ip+span+data.port+span+data.username+span+data.startTime+span+data.endTime+span+data.cmd+"</p>";
			        
			        if(data.output!="")
			    	{
			        	 html+="<p class='title'>输出:</p>";
					     html+="<p class='out'>"+data.output.replace(/\n/g,"<br>").replace(/\r/g,"")+"</p>";
			    	}
			       
			        
			        if(data.errMsg!="")
			        	{
					        html+="<p class='title'>错误</p>";
					        html+="<p class='error'>"+data.errMsg+"</p>";
					        html+="</div>";
			        	}
			        
			        html+="<hr>";
			        
			        $("#remotessh_result").prepend(html);
			        $("#remotessh_result div").first().show(500);
			    }  
			});
		}
		
		function remote_shortcut()
		{
			
		}
</script>
